package com.ziyueyuwen.xiniao.controller.student.course;

import com.suyeer.basic.util.HttpResUtil;
import com.ziyueyuwen.xiniao.base.HttpResContent;
import com.ziyueyuwen.xiniao.bean.vo.ZyClassVO;
import com.ziyueyuwen.xiniao.service.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

import static com.ziyueyuwen.xiniao.base.BaseUtil.saveErrorMsgAndData;
import static com.ziyueyuwen.xiniao.base.BaseUtil.saveSuccessMsgAndData;

/**
 * @author wancheng  on 2018/12/22.
 */
@Controller
@RequestMapping("/student/course")
public class StudentCourseController {

    @Autowired
    ClassService classService;

    @RequestMapping(value = "/get_student_course.do")
    public void getStudentCourse(HttpServletRequest request,
                                 HttpServletResponse response) {
        HttpResContent<List<ZyClassVO>> hrc = new HttpResContent<>(request, response);
        hrc.setFuncDes("获取学生的课程列表");
        try {
            if (hrc.isNotLogin()) {
                throw new IllegalAccessException("未绑定学习账号!");
            }
            String studentAccount = hrc.getUserInfo().getUserAccount();
            List<ZyClassVO> res = classService.getClassRecord(studentAccount);
            saveSuccessMsgAndData(hrc, res);
        } catch (IllegalAccessException e) {
            saveErrorMsgAndData(hrc, e);
        } catch (Exception e) {
            e.printStackTrace();
            saveErrorMsgAndData(hrc, e);
        } finally {
            HttpResUtil.writeResult(hrc, true);
        }
    }
}
